package com.example.trb.service.work;

import com.example.trb.dto.ObjectDTO;
import com.example.trb.entity.WorkExperience;
import com.example.trb.mapper.WorkExperienceMapper;
import com.example.trb.util.result.SysReturnCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class WorkExperienceService {
    @Autowired
    WorkExperienceMapper weMapper;

    public ObjectDTO update(WorkExperience data) {
        weMapper.updateById(data);
        return new ObjectDTO(null, SysReturnCode.OK);
    }

    public ObjectDTO removeById(Integer id) {
        weMapper.deleteById(id);
        return new ObjectDTO(null, SysReturnCode.OK);
    }


    public ObjectDTO updateStatusById(Integer id, String status) {
        weMapper.updateStatusById(id, status);
        return new ObjectDTO(null, SysReturnCode.OK);
    }

    public ObjectDTO save(WorkExperience data) {
        weMapper.insert(data);
        return new ObjectDTO(data.getId(), SysReturnCode.OK);
    }

    public ObjectDTO listByUserId(Integer userId) {
        Map<String, Object> queryMap = new HashMap<>();
        queryMap.put("user_id", userId);
        List<WorkExperience> result = weMapper.selectByMap(queryMap);
        return new ObjectDTO(result, SysReturnCode.OK);
    }

    public ObjectDTO getById(Integer id) {
        WorkExperience result = weMapper.selectById(id);
        return new ObjectDTO(result, SysReturnCode.OK);
    }
}
